Filtering values from dictionaries in Python